package Newsblog;
//小白月赛64小杜捕鱼

import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;

/**
 * @author :chenjie
 * @date :Created 2022/12/30 19:41
 */
public class XiaoDuFishing {
    static class Pall{
        int x;
        int y;

        public Pall(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }
    static int n,m;
    static char[][]arr=new char[1010][1010];
    static boolean[][]st=new boolean[1010][1010];
    static int max=0;
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        n=sc.nextInt();
        m=sc.nextInt();
        sc.nextLine();
        for (int i = 0; i < n; i++) {
            String s=sc.nextLine();
            arr[i] = s.toCharArray();
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if(arr[i][j]=='#'){
                    max=Math.max(i+ j,max);
                    max=Math.max(n-1-i+m-1-j,max);
                    max=Math.max(n-1-i+ j,max);
                    max=Math.max(i+m-1-j,max);
                }
            }
        }
//        bfs();
        System.out.println(max);

    }
    static void bfs(){
        Queue<Pall>queue=new ArrayDeque<>();
        queue.add(new Pall(0,0));
        while (!queue.isEmpty()){
            Pall remove = queue.remove();
            st[remove.x][remove.y]=true;
            if(arr[remove.x][remove.y]=='#'){
                max=Math.max(remove.x+ remove.y,max);
                max=Math.max(n-1-remove.x+m-1-remove.y,max);
                max=Math.max(n-1-remove.x+ remove.y,max);
                max=Math.max(remove.x+m-1-remove.y,max);
            }
            int[]dx={-1,1,0,0};
            int[]dy={0,0,-1,1};
            for (int i = 0; i < 4; i++) {
                int a= remove.x+dx[i],b= remove.y+dy[i];
                if(a>=0&&b>=0&&a<n&&b<m&&!st[a][b]){
                    queue.add(new Pall(a,b));
                }
            }
        }
    }
}
